/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package jpa.entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Giovanni
 */
@Entity
@Table(name = "invite")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Invite.findAll", query = "SELECT i FROM Invite i"),
    @NamedQuery(name = "Invite.findByEventId", query = "SELECT i FROM Invite i WHERE i.invitePK.eventId = :eventId"),
    @NamedQuery(name = "Invite.findBySender", query = "SELECT i FROM Invite i WHERE i.invitePK.sender = :sender"),
    @NamedQuery(name = "Invite.findByReceiver", query = "SELECT i FROM Invite i WHERE i.invitePK.receiver = :receiver")})
public class Invite implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected InvitePK invitePK;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "invite")
    private Collection<Ack> ackCollection;
    @JoinColumn(name = "EVENT_ID", referencedColumnName = "ID", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Event event;
    @JoinColumn(name = "SENDER", referencedColumnName = "MAIL", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private User user;
    @JoinColumn(name = "RECEIVER", referencedColumnName = "MAIL", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private User user1;

    public Invite() {
    }

    public Invite(InvitePK invitePK) {
        this.invitePK = invitePK;
    }

    public Invite(int eventId, String sender, String receiver) {
        this.invitePK = new InvitePK(eventId, sender, receiver);
    }

    public InvitePK getInvitePK() {
        return invitePK;
    }

    public void setInvitePK(InvitePK invitePK) {
        this.invitePK = invitePK;
    }

    @XmlTransient
    public Collection<Ack> getAckCollection() {
        return ackCollection;
    }

    public void setAckCollection(Collection<Ack> ackCollection) {
        this.ackCollection = ackCollection;
    }

    public Event getEvent() {
        return event;
    }

    public void setEvent(Event event) {
        this.event = event;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public User getUser1() {
        return user1;
    }

    public void setUser1(User user1) {
        this.user1 = user1;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (invitePK != null ? invitePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Invite)) {
            return false;
        }
        Invite other = (Invite) object;
        if ((this.invitePK == null && other.invitePK != null) || (this.invitePK != null && !this.invitePK.equals(other.invitePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "jpa.entities.Invite[ invitePK=" + invitePK + " ]";
    }
    
}
